package com.service;
import static com.def.GenericDef.E_XPBISCUS_INVALID_INPUT;
import static com.def.GenericDef.RETURN_CODE_OK;
import static com.def.GenericDef.RETURN_CODE_SET_ERROR;
import static com.def.GenericDef.RETURN_CODE_UNKNOWN;
import static com.def.GenericDef.RETURN_MESG_OK;
import static com.def.GenericDef.TRX_OUT;
import static com.def.GenericDef._NORMAL;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.dao.IBisOpeDao;
import com.dao.IRetPrdInfoDao;
import com.dao.ISpcRetMfgDataDao;
import com.icim.service.ICIMBaseService;
import com.model.Bis_ope;
import com.model.Bis_opeId;
import com.model.Ret_prd_info;
import com.model.Spc_ret_mfg_data;
import com.tx.Xpspcretdata.XpspcretdataI;
import com.tx.Xpspcretdata.XpspcretdataO;
import com.tx.Xpspcretdata.XpspcretdataOA;
import com.util.MqOpe;
import com.util.Util;

@Scope("prototype")
@Service("XpspcretdataService")
public class XpspcretdataService extends ICIMBaseService{
	private static Logger logger = Logger.getLogger(XpbiscusService.class);
	@Autowired
	private XpspcretdataI inTrx;
	@Autowired
	private XpspcretdataO outTrx;
	@Autowired
	private ISpcRetMfgDataDao spcRetMfgDataDao; 
	@Autowired
	private IBisOpeDao bisOpeDao;
	@Autowired
	private MqOpe mqOpe;
	@Autowired
	private XpmlitemService xpmlitemService;
	@Autowired
	private IRetPrdInfoDao retPrdInfoDao;
	
	private String gszMsgBuf = "";

	private Timestamp gEvtTimestamp;
	private Double gEvtTimeD;
	
	public String subMainProc(String strInMsg) {
		Session session = spcRetMfgDataDao.getCrSession();
		long rtnCode = _NORMAL;
		String outMsg = null;

		gszMsgBuf = "";
		gEvtTimestamp = Util.getCurrentTimestamp();
		gEvtTimeD = Util.getDoubleTime();
		inTrx = new XpspcretdataI();
		outTrx = new XpspcretdataO();
		outTrx.setTrx_id("XPSPCRET");
		outTrx.setRtn_code(String.valueOf(RETURN_CODE_SET_ERROR));
		outTrx.setType_id(TRX_OUT);

		mqOpe = new MqOpe();

		try {
			inTrx = (XpspcretdataI) mqOpe.inStr2Obj(strInMsg, inTrx);
			logger.info("InTrx is " + strInMsg);

			rtnCode = subMainProc2(inTrx.getAction_flg().toCharArray()[0]);
			if (rtnCode != _NORMAL) {
				TransactionAspectSupport.currentTransactionStatus()
						.setRollbackOnly();
				outTrx.setRtn_code(String.valueOf(rtnCode));
				outTrx.setRtn_msg(gszMsgBuf);
			} else {
				outTrx.setRtn_code(String.valueOf(RETURN_CODE_OK));
				outTrx.setRtn_msg(RETURN_MESG_OK);
				session.flush();
			}
		} catch (Exception ex) {
			TransactionAspectSupport.currentTransactionStatus()
					.setRollbackOnly();
			outTrx.setRtn_msg(ex.toString());
			outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
			logger.error(Util.stackTraceToString(ex));
		} finally {
			outMsg = mqOpe.obj2Str(outTrx);
			return outMsg;
		}
	}

	/**
	 * Real action type
	 * 
	 * @param actionType
	 * @return
	 */
	private long subMainProc2(char actionType) {
		long lRc = _NORMAL;
		switch (actionType) {
		case 'Q': {
			lRc = getSpcData();
			if (lRc != _NORMAL) {
				return lRc;
			}
			break;
		}
		default: {
			gszMsgBuf = "Invalide type input: [" + actionType + "]";
			return E_XPBISCUS_INVALID_INPUT;
		}
		}

		return lRc;
	}
	private long getSpcData(){
		String prd_seq_id_fk = inTrx.getPrd_seq_id_fk();
		String mes_id = inTrx.getMes_id();
		
		if(!("".equals(inTrx.getProc_id())) && null != inTrx.getProc_id()){
			String hql2 = "From Bis_ope where proc_id = '" + inTrx.getProc_id() + "'";
			
			List<Bis_ope> bis_ope_list = new ArrayList<Bis_ope>();
			
			bis_ope_list = bisOpeDao.find(hql2);
			
			if(!(bis_ope_list.isEmpty())){
				outTrx.setOpe_dsc(bis_ope_list.get(0).getOpe_dsc());
			}else {
				gszMsgBuf = "站点[" + inTrx.getProc_id() + "]没有维护";
				return E_XPBISCUS_INVALID_INPUT;
			}
		}
		
		String hql = "From Spc_ret_mfg_data where prd_seq_id_fk = ? and mes_id_fk = ? "; 
					 
		List<Spc_ret_mfg_data> spcRetMfgDatas = spcRetMfgDataDao.list(hql, prd_seq_id_fk,mes_id);
		
		Ret_prd_info ret_prd_info = retPrdInfoDao.get(prd_seq_id_fk);
		
		if (ret_prd_info == null) {
			gszMsgBuf = "RET_PRD_INFO中没找到改产品["+prd_seq_id_fk+"]";
			return E_XPBISCUS_INVALID_INPUT;
		}
		
		String fab_sn = ret_prd_info.getFab_sn();
		
		if (!spcRetMfgDatas.isEmpty()){
			List<XpspcretdataOA> oary = new ArrayList<XpspcretdataOA>();
			for (Spc_ret_mfg_data spc_data : spcRetMfgDatas){
				String hql1 = "FROM Bis_ope where ope_id = ?";
				Bis_ope bisOpe = new Bis_ope();
				Bis_opeId bisOpeId = new Bis_opeId();
				bisOpeId.setOpe_id(spc_data.getOpe_id_fk());
				bisOpeId.setOpe_ver(spc_data.getOpe_ver_fk());
				bisOpe = bisOpeDao.get(bisOpeId);
				if(null == bisOpe){
					gszMsgBuf = "OPE NO["+spc_data.getOpe_id_fk()+"] is not found";
					return E_XPBISCUS_INVALID_INPUT;
				}
				if(null != spc_data.getData_value_001()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_001());
					xpspcretdataOA.setData_num("T001");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_002()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_002());
					xpspcretdataOA.setData_num("T002");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_003()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_003());
					xpspcretdataOA.setData_num("T003");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_004()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_004());
					xpspcretdataOA.setData_num("T004");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_005()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_005());
					xpspcretdataOA.setData_num("T005");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_006()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_006());
					xpspcretdataOA.setData_num("T006");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_007()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_007());
					xpspcretdataOA.setData_num("T007");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_008()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_008());
					xpspcretdataOA.setData_num("T008");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_009()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_009());
					xpspcretdataOA.setData_num("T009");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_010()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_010());
					xpspcretdataOA.setData_num("T010");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_011()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_011());
					xpspcretdataOA.setData_num("T011");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_012()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_012());
					xpspcretdataOA.setData_num("T012");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_013()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_013());
					xpspcretdataOA.setData_num("T013");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_014()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_014());
					xpspcretdataOA.setData_num("T014");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_015()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_015());
					xpspcretdataOA.setData_num("T015");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_016()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_016());
					xpspcretdataOA.setData_num("T016");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_017()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_017());
					xpspcretdataOA.setData_num("T017");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_018()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_018());
					xpspcretdataOA.setData_num("T018");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_019()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_019());
					xpspcretdataOA.setData_num("T019");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_020()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_020());
					xpspcretdataOA.setData_num("T020");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_021()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_021());
					xpspcretdataOA.setData_num("T021");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_022()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_022());
					xpspcretdataOA.setData_num("T022");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_023()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_023());
					xpspcretdataOA.setData_num("T023");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_024()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_024());
					xpspcretdataOA.setData_num("T024");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_025()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_025());
					xpspcretdataOA.setData_num("T025");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_026()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_026());
					xpspcretdataOA.setData_num("T026");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_027()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_027());
					xpspcretdataOA.setData_num("T027");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_028()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_028());
					xpspcretdataOA.setData_num("T028");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_029()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_029());
					xpspcretdataOA.setData_num("T029");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
				if(null != spc_data.getData_value_030()){
					XpspcretdataOA xpspcretdataOA = new XpspcretdataOA();
					xpspcretdataOA.setPrd_seq_id_fk(prd_seq_id_fk);
					xpspcretdataOA.setFab_sn(fab_sn);
					xpspcretdataOA.setMes_id_fk(mes_id);
					xpspcretdataOA.setRpt_usr(spc_data.getRpt_usr());
					xpspcretdataOA.setRpt_timestamp(spc_data.getRpt_timestamp().toString());
					xpspcretdataOA.setData_value(spc_data.getData_value_030());
					xpspcretdataOA.setData_num("T030");
					xpspcretdataOA.setOpe_id_fk(spc_data.getOpe_id_fk());
					xpspcretdataOA.setOpe_des(bisOpe.getOpe_dsc());
					oary.add(xpspcretdataOA);
				}
			}
			outTrx.setOary(oary);
			logger.info(oary.size());
			outTrx.setData_cnt(oary.size());
		}else {
			outTrx.setData_cnt(0);
		}
		return _NORMAL;
	}
}
